import Vue from 'vue';
import Vuex from 'vuex';
import createPersistedState from 'vuex-persistedstate';

Vue.use(Vuex);

const user = {
    namespaced: true,
    state: {
        shopId: '',
        userUn: '',
        gearToken: '',
    },
    mutations: {
        upShopId(state, id) {
            state.shopId = id;
        },
        upUserUn(state, name) {
            state.userUn = name
        },
        upToken(state, token) {
            state.gearToken = token
        },
    },
    actions: {
        ybShopId({ commit }, id) {
            commit('upShopId', id)
        },
        ybUserUn({ commit }, name) {
            commit('upUserUn', name)
        },
        ybToken({ commit }, token) {
            commit('upToken', token)
        },
    }
}

const store = new Vuex.Store({
    state: {
    },
    getters: {},
    mutations: {},
    actions: {},
    modules: {
        user
    },
    plugins: [createPersistedState({
        key: 'vueXStore',
        storage: window.localStorage
    })]
});

export default store;